<!DOCTYPE html>
<html lang="en" xmlns:th="https://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<div th:replace="common/common::html"></div>
<head>
    <meta charset="UTF-8">
    <title th:text="#{role.info}">Title</title>
    <script th:inline="javascript">
        var _gridWidth;
        var _gridHeight;
        //页面自适应
        function resizePageSize(){
            _gridWidth = $(document).width()-12;/*  -189 是去掉左侧 菜单的宽度，   -12 是防止浏览器缩小页面 出现滚动条 恢复页面时  折行的问题 */
            _gridHeight = $(document).height()-72 - 44; /* -32 顶部主菜s单高度，   -90 查询条件高度*/
        }
        $(function () {
            resizePageSize();
            var _columnWidth = _gridWidth/3;
            $("#flexigrid-id").flexigrid({
                width : _gridWidth,
                height : _gridHeight,
                url : /*[[@{queryRoleInfoListByPage}]]*/"",
                dataType : 'json',
                colModel : [
                    {display : 'roleUuid',name : 'roleUuid',width : 150,sortable : false,align : 'center',hide : 'true'},
                    {display : /*[[#{role.name}]]*/"",name : 'roleName',width : _columnWidth, sortable : true,align : 'center'},
                    {display : /*[[#{role.remarks}]]*/"",name : 'remarks',width : _columnWidth, sortable : true,align : 'center'},
                    {display : /*[[#{common.operation}]]*/"",name : 'roleUuid',width : _columnWidth, sortable : true,align : 'center',process: function(v,_trid,_row) {
                            var htmltContents = "";
                            if([[${#authorization.expression("hasRole('ROLE_gqgy_data_role_detail')")}]]){
                                htmltContents += '<a href="#" style="color: #00b1ef" class="navbar-btn" onclick="roleDetail(\'' + v + '\')">' +
                                    '<span> '
                                    + /*[[#{role.btn.detail}]]*/''
                                    +'</span> </a> ';
                            }
                            return htmltContents;
                        }}
                ],
                resizable : false, //resizable table是否可伸缩
                useRp : true,
                usepager : true, //是否分页
                autoload : false, //自动加载，即第一次发起ajax请求
                hideOnSubmit : true, //是否在回调时显示遮盖
                showcheckbox : true, //是否显示多选框
                rowhandler : rowDbclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                rowbinddata : true
            });
            query();

            $("#query-btn-id").click(function (event) {
                event.stopPropagation()
                query();
            })

            $("#allocate-auth-dialog-id").dialog({
                autoOpen : false,
                width : 400,
                modal : true,
                resizable : false,
                title: /*[[#{role.menu.allocate}]]*/'',
                buttons: [
                    {
                        text: /*[[#{common.confirm}]]*/'',
                        click: function() {
                            var roleUuid =  $("#allocate-auth-tree-id").attr("roleUuid");
                            var menuIds= [];
                            var ztreeObj = $.fn.zTree.getZTreeObj("allocate-auth-tree-id");
                            var checkNodes = ztreeObj.getCheckedNodes(true);
                            var menuArray = [];
                            $(checkNodes).each(function (index,item) {
                                menuIds.push(item.id);
                            });

                            $.ajax({
                                type: 'post',
                                async: false,
                                dataType : 'json',
                                url: /*[[@{saveRoleRefMenu}]]*/'',
                                data: [
                                    {name:"roleUuid",value:roleUuid},
                                    {name:"menuIds",value:menuIds}
                                ],
                                success: function (data) {
                                    message(data.msg);
                                    $("#allocate-auth-dialog-id").dialog('close');
                                },
                                error: function(msg){
                                    message(/*[[#{common.error}]]*/'');
                                }
                            });

                        }
                    },
                    {
                        text: /*[[#{common.cancel}]]*/'',
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                ]
            });

            $("#allocate-auth-id").click(function (event) {
                event.stopPropagation()
                // $("#allocate-auth-dialog-id").dialog('open')
                allocateAuth();
            })
            var dialogWidthAll = $(document).width();
            var dialogHeightAll = $(document).height();
            $("#role-detail-dialog-id").dialog({
                width:dialogWidthAll,
                height:dialogHeightAll,
                autoOpen : false,
                modal : true,
                resizable : false,
                title: /*[[#{role.page.detail}]]*/''
            }).removeClass("ui-dialog-content");

            $("#add-role-dialog-id").dialog({
                autoOpen : false,
                width : 400,
                modal : true,
                resizable : false,
                title: /*[[#{role.add}]]*/'',
                buttons: [
                    {
                        text: /*[[#{common.confirm}]]*/'',
                        click: function() {

                            var flag = $("#add-role-form-id input.form-control").verification({});
                            if(!flag){
                                return;
                            }
                            $("#add-role-form-id").submit();
                        }
                    },
                    {
                        text: /*[[#{common.cancel}]]*/'',
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                ]
            });

            $("#add-btn-id").click(function (event) {
                event.stopPropagation()
                $("#add-role-form-id").resetForm();
                $("#add-role-dialog-id").dialog('open')
            })

            $("#add-role-form-id").ajaxForm({
                dataType: "json",
                success : function(data) {
                    message(data.msg);
                    $("#add-role-dialog-id").dialog('close');
                    query()
                },
                error : function() {
                    message(/*[[#{common.error}]]*/'');
                }
            });

            $("#modify-role-dialog-id").dialog({
                autoOpen : false,
                width : 400,
                modal : true,
                resizable : false,
                title: /*[[#{role.modify}]]*/'',
                buttons: [
                    {
                        text: /*[[#{common.confirm}]]*/'',
                        click: function() {

                            var flag = $("#modify-role-dialog-id input.form-control").verification({});
                            if(!flag){
                                return;
                            }
                            $("#modify-role-form-id").submit();
                        }
                    },
                    {
                        text: /*[[#{common.cancel}]]*/'',
                        click: function() {
                            $( this ).dialog( "close" );
                        }
                    }
                ]
            });

            $("#modify-role-form-id").ajaxForm({
                dataType: "json",
                success : function(data) {
                    message(data.msg);
                    $("#modify-role-dialog-id").dialog('close');
                    query()
                },
                error : function() {
                    message(/*[[#{common.error}]]*/'');
                }
            });

            $("#delete-btn-id").click(function (event) {
                event.stopPropagation();
                var ids = $("#flexigrid-id").getFlexigridiAttrByIndex(0);
                //console.info("roleId:" + ids)
                if(ids.length == 0){
                    message(/*[[#{common.select.more}]]*/'');
                    return;
                }
                $.ajax({
                    type: 'post',
                    async: false,
                    dataType : 'json',
                    url: /*[[@{deleteRoleById}]]*/'',
                    data: [{name:"roleUuidArray",value:ids}],
                    success: function (data) {
                        // console.info(data)
                        message(data.msg);
                        query();
                    },
                    error: function(msg){
                        message(/*[[#{common.error}]]*/'');
                    }
                });
            })

        });//ready

        function query() {
            var roleName = $("#role-name-id").val();
            $("#flexigrid-id").flexOptions({
                extParam:[
                    {name:"roleName",value:roleName}
                ]
            }).flexReload();

        }
        var allocateSetting = {
            check: {
                enable: true
            },
            data: {
                simpleData: {
                    enable: true
                }
            }
        };
        function allocateAuth() {
            var ids = $("#flexigrid-id").getFlexigridiAttrByIndex(0);
            //console.info("roleId:" + ids)
            if(ids.length != 1){
                message(/*[[#{common.select.one}]]*/'');
                return;
            }
            $("#allocate-auth-tree-id").attr("roleUuid",ids);
            $.ajax({
                type: 'post',
                async: false,
                dataType : 'json',
                url: /*[[@{queryMenuTree}]]*/'',
                data: [{name:"roleUuid",value:ids}],
                success: function (data) {
                    // console.info(data)
                    $.fn.zTree.init($("#allocate-auth-tree-id"), allocateSetting, data);
                    $("#allocate-auth-dialog-id").dialog('open');
                },
                error: function(msg){
                    message(/*[[#{common.error}]]*/'');
                }
            });

        }

        function roleDetail(roleUuid) {
            var url = /*[[${#request.getContextPath()}]]*/"";
            url +="/role/rolePageDetail?roleUuid=" + roleUuid;
            // location.href = url;
            $("#role-detail-dialog-id").dialog('open');
            $("#role-detail-iframe-id").attr("src",url);

        }

        function rowDbclick(r) {
            //console.info(r);
            $(r).dblclick(function (event) {
                event.stopPropagation();
                var cl = $(this).attr("ch").split("_FG$SP_");
                // console.info(cl);
                $("#modify-role-uuid").val(cl[0]);
                $("#modify-role-name-id").val(cl[1]);
                $("#modify-role-remarks-id").val(cl[2]);
                $("#modify-role-dialog-id").dialog('open')
            });
        }

    </script>
    <style>
        body{
            background-color: #E6E6FA
        }
    </style>
</head>
<body>
<nav style="display: flex;flex-direction: row;margin-left: 10px;align-items: center">
    <div sec:authorize="hasRole('ROLE_gqgy_data_role_query')">
        <span th:text="#{role.name}"></span>
        <input  style="margin-left: 10px;" id="role-name-id">
        <a id="query-btn-id" class="navbar-btn" href="#" style="margin-left: 10px" >
            <i class="glyphicon glyphicon-zoom-in"></i>
            <span th:text="#{common.query}"></span>
        </a>
    </div>
    <a sec:authorize="hasRole('ROLE_gqgy_data_role_allow')" id="allocate-auth-id" href="#" class="navbar-btn" style="margin-left: 10px">
        <i class="glyphicon glyphicon-random"></i>
        <span th:text="#{role.menu.allocate}"></span>
    </a>
    <a sec:authorize="hasRole('ROLE_gqgy_data_role_add')" id="add-btn-id" href="#" class="navbar-btn" style="margin-left: 10px">
        <i class="glyphicon glyphicon-plus"></i>
        <span th:text="#{common.add}"></span>
    </a>
    <a sec:authorize="hasRole('ROLE_gqgy_data_role_delete')" id="delete-btn-id" href="#" class="navbar-btn" style="margin-left: 10px">
        <i class="glyphicon glyphicon-trash"></i>
        <span th:text="#{common.delete}"></span>
    </a>
</nav>
<table  sec:authorize="hasRole('ROLE_gqgy_data_role_query')" id="flexigrid-id"></table>

<div sec:authorize="hasRole('ROLE_gqgy_data_role_allow')" id="allocate-auth-dialog-id" style="display: none">
    <ul id="allocate-auth-tree-id" class="ztree"></ul>

</div>

<div sec:authorize="hasRole('ROLE_gqgy_data_role_detail')" id="role-detail-dialog-id" style="display: none">
    <iframe  id="role-detail-iframe-id" style="width: 100%;height: 100%;border: 0"></iframe>
</div>

<div sec:authorize="hasRole('ROLE_gqgy_data_role_add')" id="add-role-dialog-id" style="display: none">
    <form id="add-role-form-id" th:action="@{addRoleInfo}" method="post">
        <div class="form-group">
            <span th:text="#{role.name}"></span>
            <input class="form-control" id="add-role-name-id" type="text" name="roleName" reg="^.{1,20}$">
        </div>
        <div class="form-group">
            <span th:text="#{role.remarks}"></span>
            <input class="form-control" id="add-role-remarks-id" type="text" name="remarks" reg="^.{1,20}$">
        </div>
    </form>
</div>
<div sec:authorize="hasRole('ROLE_gqgy_data_role_update')" id="modify-role-dialog-id" style="display: none">
    <form id="modify-role-form-id" th:action="@{modifyRoleInfo}" method="post">
        <input type="hidden" name="roleUuid" id="modify-role-uuid">
        <div class="form-group">
            <span th:text="#{role.name}"></span>
            <input class="form-control" id="modify-role-name-id" type="text" name="roleName" reg="^.{1,20}$">
        </div>
        <div class="form-group">
            <span th:text="#{role.remarks}"></span>
            <input class="form-control" id="modify-role-remarks-id" type="text" name="remarks" reg="^.{1,20}$">
        </div>
    </form>

</div>
</body>
</html>